#include "files/directory.h"
#include "functional/functional.h"
#include "scanner/tv_processor.h"
#include "scanner/tv_scanner.h"
#include "settings/settings.h"

#include <algorithm>

namespace Tvimeg
{
	void TVScanner::ScanTVFolders(void) const
	{
		TVProcessor processor;

		std::for_each(Settings::GetInstance().TVSeriesBegin(), Settings::GetInstance().TVSeriesEnd(), Bind(*this, &TVScanner::Scan, processor));
	}

	void TVScanner::Scan(const Directory& directory, TVProcessor& processor) const
	{
		// get all the series folders from this directory
		Directory::DirectoryList series;
		directory.GetDirectories(series);

		// sort the series before scanning them
		std::sort(series.begin(), series.end());

		// scan each series
		std::for_each(series.begin(), series.end(), Bind(*this, &TVScanner::ScanSeries, processor));
	}

	void TVScanner::ScanSeries(const Directory& directory, TVProcessor& processor) const
	{
		// set the name of the series in the processor
		processor.SetSeriesName(directory.GetName());

		// scan the directory
		BaseScanner::Scan(directory, processor);
	}
}
